﻿//设置Cookie信息
function setCookie(name, value)
{
    var today = new Date()
    var expires = new Date()
    expires.setTime(today.getTime() + 1000 * 60 * 60 * 24 * 365)
    document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString()
}

//设置Cookie信息,并设置Cookie存在时间
function setCookieTime(name, value, time)
{
    var today = new Date()
    var expires = new Date()
    expires.setTime(today.getTime() + time)
    document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString()
}

//获取Cookie信息
function getCookie(Name)
{
    var search = Name + "="
    if (document.cookie.length > 0)
    {
        offset = document.cookie.indexOf(search)
        if (offset != -1)
        {
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1) end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
        else return ""
    }
}

//删除Cookie信息
function DeleteCookie(Name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1000 * 60 * 60 * 24 * 365);
    var cval = getCookie(Name);
    if (cval != null) document.cookie = Name + "=" + cval + ";expires=" + exp.toGMTString();
}